package com.yztc.orangeentertainment.ui.main.subscribefragment.staritem.starpicturefragment;

import android.content.Context;
import android.util.Log;

import com.yztc.orangeentertainment.bean.staritembean.PictureBean;
import com.yztc.orangeentertainment.config.SubscribeUrlConfig;
import com.yztc.orangeentertainment.http.SubscribeRetrofitService;

import java.util.Map;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by My on 2016/10/8.
 */
public class PicturreModle implements PictureContract.Modle {

    @Override
    public void getStarPictureAll(String type, Map<String, String> params, Context context, final OnLoadPictureListener loadPictureListener) {
        Retrofit retrofit=new Retrofit.Builder().baseUrl(SubscribeUrlConfig.PATH.BASE_URL).addConverterFactory(GsonConverterFactory.create()).build();
        Call<PictureBean> call=retrofit.create(SubscribeRetrofitService.class).getStarPictureAll(type,params);
        call.enqueue(new Callback<PictureBean>() {
            @Override
            public void onResponse(Call<PictureBean> call, Response<PictureBean> response) {
                if (response.isSuccessful()){
                    loadPictureListener.onSuccess(response.body().getData().getList());
                }else {
                    Log.i("qwe","wrong");
                }
            }

            @Override
            public void onFailure(Call<PictureBean> call, Throwable t) {
                loadPictureListener.onFailure((Exception) t);
            }
        });
    }
}
